<?php

/**
 * 后台首页控制器
 * @author:Cloud
 * @copyright:TcitCMS
 * @since:2014-05-12
 */

namespace Home\Controller;

class CourseController extends CommonController
{

    function _initialize()
    {
        $this->lm_id = 3;
        parent::_initialize();
    }

    function index()
    {
        $model = new \Common\Model\MenuModel();
        $menuData = $model->where('`lm_id`=3')->find();
        //for ($i = 1; $i < 10; $i++) {
        //$menuData['title' . $i . '_'] = explode('|', $menuData['title' . $i . '_']);
        //}
        //$this->assign('menuData', $menuData);
        $this->display();
    }

    function ajaxData()
    {
        parent::indexInitialize();
        $categoryModel = new \Common\Model\CategoryModel();
        $model = new \Common\Model\NewsModel();

        $pageNo = I('post.pageno', '1', 'intval');
        $pageSize = I('post.pagesize', '10', 'intval');
        $pageNum = ($pageNo - 1) * $pageSize;
        $limit = "$pageNum,$pageSize";

        $title1 = I('post.title1');
        $title2 = I('post.title2');
        $title3 = I('post.title3');
        $title4 = I('post.title4');
        if ($title1) {
            $this->map['title1'] = array('LIKE', '%' . $title1 . '%');
        }
        if ($title2) {
            $this->map['title2'] = array('LIKE', '%' . $title2 . '%');
        }
        if ($title3) {
            $this->map['title3'] = array('LIKE', '%' . $title3 . '%');
        }

        switch ($title4) {
            case 1:
                $this->map['title10'] = array(array('EQ', 0), array('EQ', ''), 'OR');
                break;
            case 2:
                $this->map['title10'] = array('GT', 0);
                break;
            default:
                break;
        }

        $count = $model->where($this->map)->count();
        $data = $model->where($this->map)->order($this->order)->limit($limit)->select();
        $this->setDefaults($data, 'title10');
        $data = array('count' => $count, 'data' => $data);
        $this->ajaxReturn($data);
    }

    function detail()
    {
        $model = new \Common\Model\NewsModel();
        $id = I('get.id', '', 'intval');
        !$id && $this->error('参数错误!');
        $data = $model->find($id);
        $this->assign('geid', $data['category']);
        $nextData = $model->where('`deleted`=0 and `lm_id`=' . $data['lm_id'] . ' and `category` =' . $data['category'] . ' and `id`<' . $data['id'])->order('id desc')->find();
        $prevData = $model->where('`deleted`=0 and `lm_id`=' . $data['lm_id'] . ' and `category` =' . $data['category'] . ' and `id`>' . $data['id'])->order('id asc')->find();
        $prevStr = $prevData ? '<a href="' . U('News/detail', array('id' => $prevData['id'])) . '">' . $prevData['title'] . '</a>' : '没有了!';
        $nextStr = $nextData ? '<a href="' . U('News/detail', array('id' => $nextData['id'])) . '">' . $nextData['title'] . '</a>' : '没有了!';
        $this->assign('prevStr', $prevStr);
        $this->assign('nextStr', $nextStr);
        parent::commonDetail($model);
    }

}

?>